﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ChanExt;
using C.Unite;
using C.Entities;

namespace ArtLand.OA.Project.Project
{
    public partial class Pro_SampleChange : CommonPageBase
    {
        public string ContentS = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                DataBaseHelper.BindDrp(Drp_MoneyType, EnumData.DataBaseEunm.MoneyType);
                txt_AddTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
                FormInfo.ShowTriggerWin(Window1, txt_REQTOR, hid_REQTOR, "/PublicModel/SelectUsers.aspx", "选择申请人");

                FormInfo.ShowTriggerWin(Window1, txt_PRJNUB, hid_PRJNUB, "/PublicModel/SelectProj.aspx", "选择项目");

                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                LoadData();
            }
        }

        protected void LoadData()
        {
            if (!string.IsNullOrEmpty(Request["pid"]))
            {
                Proj_Main pm = TbsDbSession.Default.From<Proj_Main>().Where(Proj_Main._.ID == int.Parse(Request["pid"])).ToFirst();
                txt_PRJNUB.Text = pm.PRJNUB;
            }



            if (!string.IsNullOrEmpty(Request["id"]))
            {

                Proj_Sample Sam = TbsDbSession.Default.From<Proj_Sample>().Where(Proj_Sample._.ID == int.Parse(Request["id"])).ToFirst();
                if (Sam != null)
                {
                    txt_AMOUNT.Text = Sam.AMOUNT.Value.ToString();
                    txt_PRJNUB.Text = Sam.PRJNUB;
                    txt_REMARK.Text = Sam.REMARK;
                    txt_REQTOR.Text = Sam.REQTOR;
                    txt_AddTime.Text = Sam.AddTime.Value.ToString("yyyy-MM-dd");
                    Drp_MoneyType.SelectedValue = Sam.MoneyType;
                }
                if (!string.IsNullOrEmpty(Request["s"]))
                {
                    tool1.Hidden = false;
                    tool2.Hidden = true;
                    txt_AMOUNT.Readonly = true;
                    txt_PRJNUB.Readonly = true;
                    txt_REMARK.Readonly = true;
                    txt_REQTOR.Readonly = true;
                }
                else
                {
                    tool1.Hidden = true;
                    tool2.Hidden = false;
                }
            }
            else
            {
                tool1.Hidden = true;
                tool2.Hidden = false;
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            Proj_Sample Sam = new Proj_Sample();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Sam.ID = int.Parse(Request["id"]);
                Sam.Attach();
                Sam.REQTOR = txt_REQTOR.Text;
                Sam.REMARK = txt_REMARK.Text;
                Sam.AMOUNT = Convert.ToDecimal(txt_AMOUNT.Text);
                Sam.PRJNUB = txt_PRJNUB.Text;
                Sam.AddTime = Convert.ToDateTime(txt_AddTime.Text);
                Sam.MoneyType = Drp_MoneyType.SelectedValue;
                returnvalue = TbsDbSession.Default.Update<Proj_Sample>(Sam);
            }
            else
            {
                Sam.DeAttach();

                Sam.REQTOR = txt_REQTOR.Text;
                Sam.REMARK = txt_REMARK.Text;
                Sam.AMOUNT = Convert.ToDecimal(txt_AMOUNT.Text);
                Sam.PRJNUB = txt_PRJNUB.Text;
                Sam.AddID = CookInfo.EAdminid();
                Sam.Adder = CookInfo.EAdminTrueName();
                Sam.AddTime = DateTime.Now;
                Sam.STATUS = 0;
                Sam.AddTime =Convert.ToDateTime(txt_AddTime.Text);
                Sam.MoneyType = Drp_MoneyType.SelectedValue;
                returnvalue = TbsDbSession.Default.Insert<Proj_Sample>(Sam);
            }
            if (returnvalue > 0)
            {
                Alert.Show("更新成功！", "提示", ActiveWindow.GetHideRefreshReference());
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            Proj_Sample vc = new Proj_Sample();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 1;
            TbsDbSession.Default.Update<Proj_Sample>(vc);

            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            Proj_Sample vc = new Proj_Sample();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 2;
            TbsDbSession.Default.Update<Proj_Sample>(vc);
            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }



    }
}